import MCPDemoClient from './index.js';

async function runDemo() {
  const client = new MCPDemoClient();
  
  try {
    await client.connect();

    console.log('\n=== MCP 功能演示 ===');

    // 1. 文本处理演示
    console.log('\n1. 文本处理功能:');
    const text = "Hello, MCP!";
    console.log('原始文本:', text);
    
    const wordCount = await client.processText(text, 'wordCount');
    console.log('单词数:', wordCount.count);
    
    const charCount = await client.processText(text, 'charCount');
    console.log('字符数:', charCount.count);
    
    const upperCase = await client.processText(text, 'toUpperCase');
    console.log('转换大写:', upperCase.text);

    // 2. 计算功能演示
    console.log('\n2. 计算功能:');
    const numbers = [1, 2, 3, 4, 5];
    console.log('数据集:', numbers);

    const sum = await client.calculate('sum', numbers);
    console.log(`${sum.operation}: ${sum.result}`);

    const avg = await client.calculate('average', numbers);
    console.log(`${avg.operation}: ${avg.result}`);

    const max = await client.calculate('max', numbers);
    console.log(`${max.operation}: ${max.result}`);

    const min = await client.calculate('min', numbers);
    console.log(`${min.operation}: ${min.result}`);

    // 3. 文件读取演示
    console.log('\n3. 文件读取功能:');
    try {
      // 创建一个测试文件
      const fs = await import('fs/promises');
      await fs.writeFile('test.txt', '这是一个测试文件的内容', 'utf-8');
      
      const fileContent = await client.readFile('test.txt');
      console.log('文件内容:', fileContent.content);
      
      // 清理测试文件
      await fs.unlink('test.txt');
    } catch (error) {
      console.log('文件操作失败:', error.message);
    }

    console.log('\n演示完成！');

  } catch (error) {
    console.error('演示运行失败:', error);
  }
}

// 运行演示
console.log('启动MCP客户端演示...');
runDemo(); 